/*
 * Copyright 2023-2024, Haiku Inc. All rights reserved.
 * Distributed under the terms of the MIT License.
 */

#include <debugger.h>
#include <int.h>
#include <thread.h>
#include <arch/user_debugger.h>

void arch_clear_team_debug_info(struct arch_team_debug_info *info)
{
}

void arch_destroy_team_debug_info(struct arch_team_debug_info *info)
{
    arch_clear_team_debug_info(info);
}

void arch_clear_thread_debug_info(struct arch_thread_debug_info *info)
{
}

void arch_destroy_thread_debug_info(struct arch_thread_debug_info *info)
{
    arch_clear_thread_debug_info(info);
}

void arch_update_thread_single_step()
{
}

void arch_set_debug_cpu_state(const debug_cpu_state *cpuState)
{
    iframe *frame = thread_get_current_thread()->arch_info.userFrame;

    // Map debug_cpu_state to LoongArch64 iframe
    // This is a simplified implementation
    // A complete implementation would need to map all registers correctly
    frame->reg[0] = cpuState->x[0];
    frame->reg[1] = cpuState->x[1];
    // ... map other registers
    frame->csr_era = cpuState->pc;
}

void arch_get_debug_cpu_state(debug_cpu_state *cpuState)
{
    arch_get_thread_debug_cpu_state(thread_get_current_thread(), cpuState);
}

status_t
arch_get_thread_debug_cpu_state(Thread *thread, debug_cpu_state *cpuState)
{
    iframe *frame = thread->arch_info.userFrame;
    if (frame == NULL)
        return B_BAD_DATA;

    // Map LoongArch64 iframe to debug_cpu_state
    // This is a simplified implementation
    // A complete implementation would need to map all registers correctly
    cpuState->x[0] = frame->reg[0];
    cpuState->x[1] = frame->reg[1];
    // ... map other registers
    cpuState->pc = frame->csr_era;

    return B_OK;
}